home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
TEMP
/
GNU
/
bison
/
ActionType
< prev
next >
Wrap
Text File
|
1995-06-28
|
1KB
|
45 lines
Action Types
Previous: <Actions=>Actions> * Next: <Mid-Rule Actions=>MidRuleAct> * Up: <Semantics=>Semantics>
#Wrap on
{fH4}Data Types of Values in Actions{f}
If you have chosen a single data type for semantic values, the {fCode}$${f}
and {fCode}${fStrong}n{f}{f} constructs always have that data type.
If you have used {fCode}%union{f} to specify a variety of data types, then you
must declare a choice among these types for each terminal or nonterminal
symbol that can have a semantic value. Then each time you use {fCode}$${f} or
{fCode}${fStrong}n{f}{f}, its data type is determined by which symbol it refers to
in the rule. In this example,
#Wrap off
#fCode
exp: …
| exp '+' exp
\{ $$ = $1 + $3; \}
#f
#Wrap on
{fCode}$1{f} and {fCode}$3{f} refer to instances of {fCode}exp{f}, so they all
have the data type declared for the nonterminal symbol {fCode}exp{f}. If
{fCode}$2{f} were used, it would have the data type declared for the
terminal symbol {fCode}'+'{f}, whatever that might be.
Alternatively, you can specify the data type when you refer to the value,
by inserting {fEmphasis}<{fStrong}type{f}>{f} after the {fEmphasis}${f} at the beginning of the
reference. For example, if you have defined types as shown here:
#Wrap off
#fCode
%union \{
int itype;
double dtype;
\}
#f
#Wrap on
then you can write {fCode}$<itype>1{f} to refer to the first subunit of the
rule as an integer, or {fCode}$<dtype>1{f} to refer to it as a double.